import { parse } from 'url';
import { TableListItem, TableListParams } from './data';

function getChargeRecords(
  req: { url: any },
  res: {
    json: (
      arg0: {
        body: {
          list: TableListItem[];
          count: number,
        }
      },
    ) => void;
  },
  u: any,
) {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== '[object String]') {
    // eslint-disable-next-line prefer-destructuring
    url = req.url;
  }

  const params = (parse(url, true).query as unknown) as TableListParams;

  const dataSource: TableListItem[] = [];

  for (let i = (params.pageNum - 1) * 10; i < 10 * params.pageNum; i += 1) {
    dataSource.push({
      id: i + 1,
      fcs_id: i + 1,
      serial_num: 123,
      pay_way: 1,
      pay_account: 12335,
      amount: 12355,
      oper_uid: 1,
      settle_time: '2019-10-20',
      parent_name: '张三丰',
      name: `孙悟空${i + 1}`,
      pay_way_desc: 1,
      oper_name: '张三丰',
    });
  }

  const result = {
    code: 0,
    body: {
      list: dataSource,
      count: 30,
    },
  };

  return res.json(result);
}

export default {
  'GET /account/recharge/log_list': getChargeRecords,
};
